filedir = r'D:\Python2022\Python基础2023\data\read.txt'
# filedir1 = 'D:/pytest2.txt'


#----------------移动光标操作-------------
# fo = open(filedir,'rb')
# print('移动前光标的位置',fo.tell())
# print("移动3个光标",fo.seek(3))
# print(fo.read(2))
# print("移动后光标的位置",fo.tell())
# fo.seek(-2,1)
# print('再次移动后',fo.tell())

#--------------------读一行---------------
# print(fo.readline())
# print(fo.tell())
# print(fo.readline())
# fo.seek(0)

#------------------读所有行----------------
# print(fo.readlines())
# fo.write('123456\nhello ')
# fo.seek(0)
# print(fo.read().splitlines())


#------------------写模式--------------------
"""
w：表示文件只能写入,没有该文件则创建
w+：表示可以对文件进行读写双重操作
a+追加模式，再已经写的文本李追加写入   
"""
# fo = open(filedir1,'w+',encoding="utf-8")
# fo.write('123456\nabcdefg\n中国2021年实现全面建成小康社会')
# # print(fo.write('\ndddddd'))
# fo.seek(0)
# print(fo.readlines())
# fo.close()




#------------------with open----------------------
# inFileName  = 'D:/file1.txt'
# outFileName = 'D:/file888.txt'
#
# with open(inFileName) as ifile, open(outFileName,'w') as ofile:
#     alist=ifile.read().splitlines()
#     print(alist)
#     for one in alist:
#         # print(one)
#         if one.count(';')!= 1:
#             continue
#
#         namePart,salaryPart = one.split(';')
#
#         if namePart.count(':') != 1:
#             continue
#         if salaryPart.count(':') !=1:
#             continue
#
#         name = namePart.split(':')[1].strip()
#
#         salary = int(salaryPart.split(':')[1].strip())
#
#         income = int(salary*0.9)
#         tax    = int(salary*0.1)
#
#         outputstr = 'name: {:>10} ; salary: {:6};  tax:{:6} ; income: {:6}'.format(name,salary,tax,income)
#
#         print( outputstr)
#         ofile.write(outputstr+'\n')



# start1_data = 'D:\Python2022\Python基础2023\data\start2.txt'  # 数据存放路径
# for one in range(6,11):
#     one=str(one)
#     with open(start2_data,'a+',encoding="utf-8") as start_file:#追加模式写
#         start_file.write(one+'你好中国"\n"')


"""写"""
start2_data = 'D:\Python2022\Python基础2023\data\start1.txt'  # 数据存放路径
with open(start2_data,'w',encoding='utf-8') as start_file:
    start_file.write("这是我爱你中国")


"""读"""
start3_data = r'D:\Python2022\Python基础2023\data\read.txt'
with open(start3_data,'r',encoding='utf-8') as start_file:
    print(start_file.read().splitlines())
    # print(start_file.read())